﻿using DataUp.Model;
using System;
using System.Collections.Generic;
using System.Linq;

namespace DataUp
{
    public class Program
    {
        public static void Main(string[] args)
        {

            string mallConnectionStr = "Server=47.98.56.8;Database=lookchemcn_mall;Uid=sa;Pwd=091019100";
            SqlContext _cnMall = new SqlContext(mallConnectionStr, FreeSql.DataType.SqlServer);
            Console.WriteLine("开始查询地区数据.....");
            var ListSysTemArea = _cnMall.QueryList<System_Area>(m => true);
            Console.WriteLine($"查询出[{ListSysTemArea.Count}]条地区数据");
            ListSysTemArea.ForEach(m => 
            {
                var nextArea = _cnMall.QueryCount<System_Area>(n => n.ParentCode == m.Code);
                if (nextArea <= 0)
                {
                    var i =_cnMall.Update<System_Area>(e => new System_Area 
                    {
                        leaf = 0 
                    }, n => n.Code == m.Code);
                    if (i > 0)
                    {
                        Console.WriteLine($"修改一条leaf,Code[{m.Code}]");
                    }
                }
            });
        }
    }
}
